package cn.iocoder.yudao.module.lowcode.controller.admin.generic.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * 表单配置 VO
 * 对应 table_form 字段的 JSON 结构
 *
 * @author 芋道源码
 */
@Schema(description = "低代码 - 表单配置 VO")
@Data
public class TableFormConfigVO {

    @Schema(description = "表单布局", example = "horizontal", allowableValues = {"horizontal", "vertical", "inline"})
    private String layout = "horizontal";

    @Schema(description = "标签宽度", example = "120")
    private Integer labelWidth = 120;

    @Schema(description = "表单列数", example = "2")
    private Integer columns = 2;

    @Schema(description = "表单尺寸", example = "default", allowableValues = {"small", "default", "large"})
    private String size = "default";

    @Schema(description = "是否显示冒号", example = "true")
    private Boolean colon = true;

    @Schema(description = "字段分组配置")
    private List<FormGroupConfig> groups;

    @Schema(description = "表单验证配置")
    private FormValidationConfig validation;

    @Schema(description = "表单样式配置")
    private FormStyleConfig style;

    @Schema(description = "扩展配置")
    private Map<String, Object> extra;

    /**
     * 表单分组配置
     */
    @Schema(description = "表单分组配置")
    @Data
    public static class FormGroupConfig {

        @Schema(description = "分组名称", example = "基本信息")
        private String title;

        @Schema(description = "分组字段列表", example = "[\"name\", \"code\", \"status\"]")
        private List<String> fields;

        @Schema(description = "是否可折叠", example = "false")
        private Boolean collapsible = false;

        @Schema(description = "默认是否展开", example = "true")
        private Boolean defaultExpanded = true;

        @Schema(description = "分组描述", example = "填写基本的信息内容")
        private String description;

    }

    /**
     * 表单验证配置
     */
    @Schema(description = "表单验证配置")
    @Data
    public static class FormValidationConfig {

        @Schema(description = "验证触发方式", example = "blur", allowableValues = {"blur", "change", "submit"})
        private String trigger = "blur";

        @Schema(description = "是否显示验证图标", example = "true")
        private Boolean showIcon = true;

        @Schema(description = "验证消息显示位置", example = "bottom", allowableValues = {"top", "bottom", "inline"})
        private String messagePosition = "bottom";

        @Schema(description = "是否滚动到第一个错误字段", example = "true")
        private Boolean scrollToError = true;

    }

    /**
     * 表单样式配置
     */
    @Schema(description = "表单样式配置")
    @Data
    public static class FormStyleConfig {

        @Schema(description = "表单间距", example = "16")
        private Integer spacing = 16;

        @Schema(description = "是否显示边框", example = "false")
        private Boolean bordered = false;

        @Schema(description = "背景颜色", example = "#ffffff")
        private String backgroundColor;

        @Schema(description = "自定义CSS类名", example = "custom-form")
        private String className;

        @Schema(description = "自定义样式", example = "{\"padding\": \"20px\"}")
        private Map<String, Object> customStyle;

    }

}